package dongbai.soft.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import dongbai.soft.dao.ProductDao;
import dongbai.soft.entity.ProductEntity;
import dongbai.soft.service.ProductService;
import dongbai.soft.utils.Constant;
import dongbai.soft.utils.PageUtils;
import dongbai.soft.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;

@SuppressWarnings("unchecked")
@Service("productService")
public class ProductServiceImpl extends ServiceImpl<ProductDao, ProductEntity> implements ProductService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Map<String, Object> filter = (Map<String, Object>) params.get("filter");
        QueryWrapper<ProductEntity> wrapper = new QueryWrapper<ProductEntity>().ge("price", filter.get("min_price"))
                .like("TID", filter.get("TID")).ge("num", filter.get("num"))
                .like("name", filter.get("name")).eq("status", Constant.STATE_Y);
        if ((int) filter.get("max_price") != -1) {
            wrapper.le("price", filter.get("max_price"));
        }
        IPage<ProductEntity> page = this.page(
                new Query<ProductEntity>().getPage(params),
                wrapper
        );
        return new PageUtils(page);
    }


}